﻿/**
 * Copyright (c) 2008 Justin Etheredge http://www.codethinked.com
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Microsoft Public License (Ms-PL)
 * which accompanies this distribution, and is available at
 * http://www.opensource.org/licenses/ms-pl.html
 * If redistributing this code, this entire header must remain intact.
 * 
 * Some of the code in this application has been taken 
 * from the following sources (all of which are licensed under
 * the Ms-PL):
 * Matt Warren's Blog: http://blogs.msdn.com/mattwar/
 * MSDN: http://msdn2.microsoft.com/en-us/library/bb546158.aspx
 */

using LinqToSimpleDB;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System;
using LinqToSimpleDB.Exceptions;

namespace LinqToSimpleDBTest
{
    
    
    /// <summary>
    ///This is a test class for SimpleDBNumericHelperTest and is intended
    ///to contain all SimpleDBNumericHelperTest Unit Tests
    ///</summary>
  [TestClass()]
  public class SimpleDBNumericHelperTest
  {


    private TestContext testContextInstance;

    /// <summary>
    ///Gets or sets the test context which provides
    ///information about and functionality for the current test run.
    ///</summary>
    public TestContext TestContext
    {
      get
      {
        return testContextInstance;
      }
      set
      {
        testContextInstance = value;
      }
    }

    #region Additional test attributes
    // 
    //You can use the following additional attributes as you write your tests:
    //
    //Use ClassInitialize to run code before running the first test in the class
    //[ClassInitialize()]
    //public static void MyClassInitialize(TestContext testContext)
    //{
    //}
    //
    //Use ClassCleanup to run code after all tests in a class have run
    //[ClassCleanup()]
    //public static void MyClassCleanup()
    //{
    //}
    //
    //Use TestInitialize to run code before running each test
    //[TestInitialize()]
    //public void MyTestInitialize()
    //{
    //}
    //
    //Use TestCleanup to run code after each test has run
    //[TestCleanup()]
    //public void MyTestCleanup()
    //{
    //}
    //
    #endregion


    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatDoubleTest()
    {
      double num = 1.2F;
      int precision = 15;
      int scale = 5;
      string expected = "0000000001.20000";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatDoubleWithHighScaleTest()
    {
      double num = 41.2465554F;
      int precision = 15;
      int scale = 5;
      string expected = "0000000041.24655";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatDecimalTest()
    {
      Decimal num = 3994.488M;
      int precision = 15;
      int scale = 5;
      string expected = "0000003994.48800";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatDecimalWithHighScaleTest()
    {
      Decimal num = 3994.4885433M;
      int precision = 15;
      int scale = 5;
      string expected = "0000003994.48854";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    [DeploymentItem("LinqToSimpleDB.dll")]
    public void PadAndFormatStringTest()
    {
      string num = "55.2";
      int precision = 15;
      int scale = 5;
      string expected = "0000000055.20000";
      string actual;
      actual = SimpleDBNumericHelper_Accessor.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);      
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatLongTest()
    {
      long num = 75885;
      int precision = 15;
      int scale = 5;
      string expected = "0000075885.00000";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    [ExpectedException(typeof(InvalidNumberException))]
    public void PadAndFormatLongWithHighScaleTest()
    {
      long num = 33444475885;
      int precision = 15;
      int scale = 5;
      SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatUIntTest()
    {
      uint num = 10;
      int precision = 15;
      int scale = 5;
      string expected = "0000000010.00000";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);      
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatULongTest()
    {
      ulong num = 75;
      int precision = 15;
      int scale = 5;
      string expected = "0000000075.00000";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);
    }

    /// <summary>
    ///A test for PadAndFormatNumber
    ///</summary>
    [TestMethod()]
    public void PadAndFormatIntTest()
    {
      int num = 85;
      int precision = 15;
      int scale = 5;
      string expected = "0000000085.00000";
      string actual;
      actual = SimpleDBNumericHelper.PadAndFormatNumber(num, precision, scale);
      Assert.AreEqual(expected, actual);      
    }
  }
}
